
export const dateShortcutKeyJS = {
  data() {
    return {
      // 时间选择限制
      pickerMinDate: '',
      datePickerOptions: {
        disabledDate: time => {
          return time.getTime() > Date.now();
        }
      },
      pickerOptions: {
        shortcuts: [{
          text: '昨天',
          onClick: picker => {
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 1);
            picker.$emit('pick', [start, start]);
          }
        },
        {
          text: '本周',
          onClick: picker => {
            const end = new Date();
            const start = new Date();
            const days = new Date().getDay() == 1 ? 7 : new Date().getDay() - 1;
            start.setTime(start.getTime() - 3600 * 1000 * 24 * days);
            picker.$emit('pick', [start, end]);
          }
        },
        {
          text: '本月',
          onClick: picker => {
            const end = new Date();
            const start = new Date();
            const days = new Date().getDate() - 1;
            start.setTime(start.getTime() - 3600 * 1000 * 24 * days);
            picker.$emit('pick', [start, end]);
          }
        },
        {
          text: '过去7天',
          onClick: picker => {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 6);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '过去30天',
          onClick: picker => {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 29);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近六个月',
          onClick: picker => {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 180);
            picker.$emit('pick', [start, end]);
          }
        }
        ],
        onPick: ({ maxDate, minDate }) => {
          this.pickerMinDate = minDate.getTime();
          if (maxDate) {
            this.pickerMinDate = '';
          }
        },
        disabledDate: time => {
          if (this.pickerMinDate !== '') {
            const day30 = (30 - 1) * 24 * 3600 * 1000;
            let maxTime = this.pickerMinDate + day30;
            if (maxTime > new Date()) {
              maxTime = new Date();
            }
            return time.getTime() > maxTime;
          }
          return time.getTime() > Date.now();
        }
      }
    };
  }
};
